import Vue from 'vue'
import Vuex from 'vuex'

import { getShopData } from '../api/shop'
import { getGoodsData } from "../api/shop";
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    shopData: {

    },
    goodsDat:{

    }
  },
  getters: {

  },
  mutations: {
    // 里面的方法名大写
    SET_SHOP_DATA(state, data) {
      state.shopData = data
    },
    GET_GOODS_DATA(state,data){
      state.goodsDat=data
    }
  },
  actions: {
    get_shop_data({ commit }) {
      return new Promise(async (res, rej) => {
        // 发送ajax请求
        let { data } = await getShopData()
        console.log(data.data);
        // 把数据存到mutations
        commit('SET_SHOP_DATA', data.data)
        res(data)
      })
    },
    get_goods_data({commit}){
      return new Promise(async(res,rej)=>{
        let {data}=await getGoodsData()
        console.log(data);
        commit('GET_GOODS_DATA',data)
        res(data)
      })
    }
  },
  modules: {
  }
})
